<?php
/**
 * MageWorx
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the MageWorx EULA that is bundled with
 * this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.mageworx.com/LICENSE-1.0.html
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@mageworx.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade the extension
 * to newer versions in the future. If you wish to customize the extension
 * for your needs please refer to http://www.mageworx.com/ for more information
 * or send an email to sales@mageworx.com
 *
 * @category   MageWorx
 * @package    MageWorx_Adminhtml
 * @copyright  Copyright (c) 2009 MageWorx (http://www.mageworx.com/)
 * @license    http://www.mageworx.com/LICENSE-1.0.html
 */

/**
 * MageWorx Adminhtml extension
 *
 * @category   MageWorx
 * @package    MageWorx_Adminhtml
 * @author     MageWorx Dev Team <dev@mageworx.com>
 */

class MageWorx_Adminhtml_Block_Deliveryzone_Shippingmethods_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
    public function __construct()
    {
      parent::__construct();
      $this->setId('zone_tabs');
      $this->setDestElementId('edit_form');
      $this->setTitle(Mage::helper('deliveryzone')->__('Zone Settings'));
    }

    protected function _beforeToHtml()
    {
        $this->addTab('general', array(
          'label'     => Mage::helper('deliveryzone')->__('General Settings'),
          'title'     => Mage::helper('deliveryzone')->__('General Settings'),
          'content'   => $this->getLayout()->createBlock('mageworx/deliveryzone_shippingmethods_edit_tab_general')->toHtml(),
        ));

        $shipping     = Mage::getSingleton('shipping/config');
        $configFields = Mage::getSingleton('adminhtml/config');
        $section      = 'carriers';
        $sections     = $configFields->getSections($section);
        $section      = $sections->$section->groups;

        foreach ($shipping->getAllCarriers() as $carrier) {
            if (!$section->{$carrier->getId()}) continue;
            $this->addTab('carrier_'.$carrier->getId(), array(
                'label'     => Mage::helper('deliveryzone')->__('%s', $section->{$carrier->getId()}->label),
            	'title'     => Mage::helper('deliveryzone')->__('%s', $section->{$carrier->getId()}->label),
                'content'   => $this->getLayout()->createBlock('mageworx/deliveryzone_shippingmethods_edit_tab_shippingmethod')
                    ->setCarrier($carrier)
                    ->setLabel($section->{$carrier->getId()}->label)
                    ->toHtml(),
            ));
        }

        return parent::_beforeToHtml();
    }
}